package com.rightsidetech.http.controller.admin.mall;

import com.github.pagehelper.PageInfo;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.mall.dto.request.gift.GiftPageReq;
import com.rightsidetech.mall.dto.request.gift.SaveGiftReq;
import com.rightsidetech.mall.dto.request.gift.UpdateGiftReq;
import com.rightsidetech.mall.dto.response.gift.GiftDetailResp;
import com.rightsidetech.mall.dto.response.gift.GiftPageResp;
import com.rightsidetech.mall.service.MallGiftCommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/mall_gift/")
@ShenyuSpringMvcClient(path = "/admin/mall_gift/**")
@Api(tags = "Admin: 换购商品相关")
public class MallGiftCommodityController extends BaseController {

    @Resource
    private MallGiftCommodityService mallGiftCommodityService;

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/save")
    @ApiOperation("创建换购商品")
    public ResponseData save(@RequestBody SaveGiftReq req) throws Exception{
        Long loginInfoId = Long.parseLong(getAttribute());
        String loginName = getLoginName();
        if(null == loginInfoId || null == loginName){
            return ResponseData.fail("未找到登录人");
        }
        return mallGiftCommodityService.saveGift(req, loginName, loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public ResponseData<PageInfo<GiftPageResp>> pageGift(GiftPageReq req){
        return mallGiftCommodityService.page(req);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/update")
    @ApiOperation("修改换购商品")
    public ResponseData update(@RequestBody UpdateGiftReq req) throws Exception{
        Long loginInfoId = Long.parseLong(getAttribute());
        String loginName = getLoginName();
        if(null == loginInfoId || null == loginName){
            return ResponseData.fail("未找到登录人");
        }
        return mallGiftCommodityService.update(req, loginName, loginInfoId);
    }


    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/detail")
    @ApiOperation("换购商品详情")
    public ResponseData<GiftDetailResp> details(Long id){
         return mallGiftCommodityService.detail(id);
    }

}
